home *** CD-ROM | disk | FTP | other *** search
- Path: news.sprintlink.net!datalytics!news
- From: Rob Stewart <stew@datalytics.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Are Pure Functions always Virtual????
- Date: 8 Jan 1996 19:40:24 GMT
- Organization: Datalytics, Inc
- Message-ID: <4crrv8$h4r@gold.datalytics.com>
- References: <4cilse$5li@news2.deltanet.com>
- NNTP-Posting-Host: pc071.datalytics.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
-
- olivas@deltanet.com (Sergio Olivas) wrote:
- >
- >I have a base class for accessing databases (BC++), the base class is
- >made of only pure virtual functions. Two derived classes are written,
- [snip]
- >Since I've heard that using virtual functions really eats into the 64k
- >automatic data segment, as well as adding overhead, is the
-
- This is true only insofar as there is a vtable (virtual
- function table) for classes with virtual functions--though it
- is shared among all instances of each class--and that each
- object with virtual functions carries a pointer to the vtable.
-
- 'virtual'
- >keyword really needed. -- and does it make any difference, assuming
- >I'm not going to further derive another class from the newly derived
- >class (in this case DB_BASE_PDX) ???
-
- >eg..
- > class DB_BASE {
- >{ ...
- > virtual int NextRecord(int TableID) = 0;
- > ..^^^^^ is this needed?
- > };
-
- >The derived classes are something like
- > class DB_BASE_PDX : public DB_BASE
- > {
- > ...
- > int NextRecord(int TableID);
- > ...
- > }
-
- Absolutely. There is no such thing as a "pure" function.
- There are only "pure virtual" functions. In other words,
- "pure" is a modifier of "virtual" and not of "function."
-
- The only purpose of a "pure virtual" function is to specify an
- interface required of classes derived from the abstract base
- class (so named because you cannot instantiate an object of a
- class with pure virtual functions--it is, thus, abstract).
- The virtual function mechanism is what allows for this
- interface commonality among classes derived from the ABC. You
- can then declare a pointer to the ABC and assign it the
- address of any object of a derived type. All derived types
- will adhere to the ABC's interface, so the ABC pointer can
- invoke that interface on any derived class object.
-
- --
- Robert Stewart | My opinions are usually my own.
- Datalytics, Inc.
- (513)226-7700
- stew@datalytics.com
-
-
-